import 'package:flutter/material.dart';
import 'package:flutterdemo/0demo/provider/02my_demo/provider_test2/shared_data.dart';
import 'package:provider/provider.dart';

class TextWidget1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print("TextWidget1 build");
    // 这种方式context相关全部重建
//    final userModel = Provider.of<SharedData>(context).userModel;

    // 这种方式与consumer一致
//    final userModel = context.watch<SharedData>().userModel;

    // 这种方式修改SharedData中其他属性不会重建，与selector一致，最细的粒度
    final userModel = context.select((SharedData sharedData) => sharedData.userModel);
    return Container(
      child: Text(
        userModel == null ? "null" : userModel.toString(),
      ),
    );
  }
}
